# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import os
import sys

if __name__ == "__main__":
    len = len(sys.argv)
    if len != 2:
        print("please input the station\n")
        quit()

    fn = sys.argv[1]
    fn = fn.split(",")

    # {
    #    "addtask": {
    #        "op1": [[0, 22], [1, 22], ...],
    # }
    ret = {}

    for file in fn:
        with open("./log/split/%s" % file, 'r') as f:
            for row in f:
                d = row.strip()
                d = d.split(",")

                sn = d[2]
                tmp = [d[3], d[4]]
                name = d[5]

                if sn not in ret:
                    ret[sn] = {}

                wsn_data = ret[sn]

                if name not in wsn_data:
                    wsn_data[name] = []

                data = wsn_data[name]

                data.append(tmp)

    if not os.path.exists("./log/pic"):
        os.makedirs("./log/pic")

    for sn in ret:
        sn_data = ret[sn]

        plt.figure(figsize=(10, 5))
        plt.grid()

        for k in sn_data:
            x = []
            y = []

            k_data = sn_data[k]

            for d in k_data:
                x.append(int(d[0]))
                y.append(int(d[1]))

            plt.plot(x, y)

        plt.ylabel("ms")
        plt.title(sn)

        plt.savefig("./log/pic/%s.png" % sn)
        plt.show()
